#include <thrust/device_vector.h>
#include <thrust/sort.h>
#include <thrust/random.h>
#include <iostream>
#include <iomanip>


#include "sort_compare.h"

  size_t N = 1<<25;
void testGenerate()
{
  thrust::host_vector<int> h_vec(N);
  thrust::default_random_engine rng(123456);
  thrust::uniform_int_distribution<int> dist(1, N);  
  thrust::generate(h_vec.begin(), h_vec.end(), [&](){ return dist(rng); });
}

thrust::host_vector<int> h_vecGlobal(N);
void beforetestSort()
{
  thrust::default_random_engine rng(123456);
  thrust::uniform_int_distribution<int> dist(1, N);  
  thrust::generate(h_vecGlobal.begin(), h_vecGlobal.end(), [&](){ return dist(rng); });

}

thrust::device_vector<int> d_vecGlobal;
void testSort()
{
  // transfer data to the device
  thrust::device_vector<int> d_vecGlobal = h_vecGlobal;
  // sort data on the device
  thrust::sort(d_vecGlobal.begin(), d_vecGlobal.end());
}

void testCopy()
{
  thrust::copy(d_vecGlobal.begin(), d_vecGlobal.end(), h_vecGlobal.begin());
}


void testInt()
{
  thrust::host_vector<int> h_vec(N);
  thrust::default_random_engine rng(123456);
  thrust::uniform_int_distribution<int> dist(1, N);


thrust::generate(h_vec.begin(), h_vec.end(), [&](){ return dist(rng); });
// transfer data to the device
thrust::device_vector<int> d_vec = h_vec;
// sort data on the device
thrust::sort(d_vec.begin(), d_vec.end());
// transfer data back to host
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());

}

void testFloat()
{


  thrust::device_vector<float> keys(N);
  thrust::default_random_engine rng(123456);
  thrust::uniform_int_distribution<int> dist(1, N);
  for(size_t i = 0; i < keys.size(); i++){
    keys[i] = dist(rng)/2.0f;
  }    

  thrust::sort(keys.begin(), keys.end()); 
}

void testAnother(void)
{
// generate 16M random numbers on the host
thrust::host_vector<int> h_vec(N);
thrust::generate(h_vec.begin(), h_vec.end(), rand);
// transfer data to the device
thrust::device_vector<int> d_vec = h_vec;
// sort data on the device
thrust::sort(d_vec.begin(), d_vec.end());
// transfer data back to host
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());

}



// int main(void)
// {


//   cout << "sorting testAnother"<< endl;
//   cout << Measure::execution(testAnother)<< endl;  


//   cout << "sorting integers"<< endl;
//   cout << Measure::execution(testInt)<< endl;

//   cout << "sorting testGenerate"<< endl;
//   cout << Measure::execution(testGenerate)<< endl;

//   beforetestSort();

//   cout << "sorting testSort"<< endl;
//   cout << Measure::execution(testSort)<< endl;

//   cout << "sorting testCopy"<< endl;
//   cout << Measure::execution(testCopy)<< endl;

  
//   // std::cout << "sorting float";
//   // cout << Measure::execution(testFloat)<< endl;
  


//   return 0;
// }

